package com.situ.ssh.dao.impl;

import com.situ.ssh.dao.IUserDao;
import com.situ.ssh.entity.User;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository
public class UserDaoImpl extends HibernateDaoSupport implements IUserDao {

    @Resource
    public void setMySessionFactory(SessionFactory sessionFactory){
        super.setSessionFactory(sessionFactory);
    }

    public void save(User user) {
        getHibernateTemplate().save(user);
    }

    public void deleteById(User user) {
        getHibernateTemplate().delete(user);
    }

    public void update(User user) {
        getHibernateTemplate().update(user);
    }

    public User selectById(Integer id) {
        return getHibernateTemplate().get(User.class, id);
    }

    public List<User> selectAll() {
        String hql = "from User";
        return (List<User>) getHibernateTemplate().find(hql);
    }
}
